//
// Created by 吴锐 on 2022/2/25.
//

#include "iostream"

using namespace std;

class Person {
public:
    int *m_Age;

    Person(int age) {
        m_Age = new int(age);
    }

    ~Person() {
        if (m_Age != NULL) {
            delete m_Age;
            m_Age = NULL;
        }
    }

    Person& operator=(Person &p) {
        if (m_Age != NULL) {
            delete m_Age;
            m_Age = NULL;
        }
        m_Age = new int(*p.m_Age);
        return *this;
    }
};

void test01() {
    Person p1(18);
    Person p2(20);
    Person p3(30);

    p3 = p2 = p1;

    cout << *p1.m_Age << endl;
    cout << *p2.m_Age << endl;
    cout << *p3.m_Age << endl;
}

int main() {
    test01();

    int a = 10;
    int b = 20;
    int c = 30;
    c = b = a;
    cout << a << endl;
    cout << b << endl;
    cout << c << endl;
    return 0;
}